<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\TongUserOpera;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Models\Administrator;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class TongUserOperaController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new TongUserOpera(['adminInfo','userInfo']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->model()->orderBy('id', 'desc');
            $grid->column('adminInfo',' 操作人')->display(function($value){
                return $this->adminInfo['name'];
            });
            $grid->column('u_id','用户')->display(function($value){
                return '【昵称：'.$this->userInfo['nickname'].'】--【用户ID：'.$value.'】';
            });
            $grid->column('type','操作类型')->display(function($value){
                if($value==1){
                    return '钱包充值';
                }
                if($value==2){
                    return '复购券充值';
                }
                if($value==3){
                    return '店铺指定';
                }
                if($value==4){
                    return '修改身份';
                }
                if($value==5){
                    return '修改邀请人';
                }
            });
            $grid->column('desc','操作详情')->view('admin.users.opear.desc');
            $grid->column('created_at','操作时间');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->panel();
                $filter->equal('id')->width(3);
                $filter->equal('u_id','用户id')->width(3);
                $admin_arr = Administrator::query()->pluck('name','id');
                $filter->equal('admin_id','管理员')->select($admin_arr)->width(3);
                $filter->equal('type','操作类型')->select([1=>'钱包',2=>'复购',3=>"店铺",4=>'身份'])->width(3);
            });

            // 禁用添加按钮
            $grid->disableCreateButton();
            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->disableDelete();
                $actions->disableEdit();
                $actions->disableQuickEdit();
                $actions->disableView();

            });
            $grid->showActions(false);
            $grid->disableRowSelector();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new TongUserOpera(), function (Show $show) {
            $show->field('id');
            $show->field('admin_id');
            $show->field('type');
            $show->field('u_id');
            $show->field('desc');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new TongUserOpera(), function (Form $form) {
            $form->display('id');
            $form->text('admin_id');
            $form->text('type');
            $form->text('u_id');
            $form->text('desc');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
